package com.xxc.response.config

import com.xxc.common.anotation.POKO
import com.xxc.response.handler.ResponseResultHandler
import com.xxc.response.interceptor.ResponseResultInterceptor
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.AutoConfigureAfter
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

/**
 * 注册拦截器
 */
@POKO
@Configuration
@AutoConfigureAfter(WebMvcAutoConfiguration::class)
class ResponseConfig:WebMvcConfigurer{

    override fun addInterceptors(registry: InterceptorRegistry) {
        super.addInterceptors(registry)
        registry.addInterceptor(responseResultInterceptor()).addPathPatterns("/**")
    }

    @Bean
    fun responseResultInterceptor() = ResponseResultInterceptor()

    @Bean
    fun responseResultHandler() = ResponseResultHandler()
}